import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'listLength'
})
export class ListLengthPipe implements PipeTransform {
  transform(val: any, num: number, datum: number) {
    const vals = JSON.parse(JSON.stringify(val));
    if (Array.isArray(vals) && vals.length > 0) {
        const length = vals.length;
        if (num === 0) {
          vals.length = parseInt(((length - 1) / datum) + '', 10) * datum + datum;
        } else if (num > 0) {
          if (vals.length < num) {
            vals.length = num;
          } else if (!!datum) {
            vals.length = parseInt(((length - 1) / datum) + '', 10) * datum + datum;
          }
        }
      }
      return vals;
  }
}
